package com.dubboService.way1;

import com.base.UserService;
import com.base.UserServiceImpl;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;

import java.io.IOException;

public class DubboProvider {
    public static void main(String[] args) throws IOException {
        //暴露UserService服务
        //1、application
        ApplicationConfig applicationConfig=new ApplicationConfig("sample-provider");
        //2、protocol -dubbo协议
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(20880);
        //3、register
        //直连的方式，不暴露到注册中心
        RegistryConfig registryConfig=new RegistryConfig(RegistryConfig.NO_AVAILABLE);
        //4、service
        ServiceConfig<UserServiceImpl> serviceConfig=new ServiceConfig<UserServiceImpl>();
        serviceConfig.setInterface(UserService.class);
        serviceConfig.setRef(new UserServiceImpl());
        //5、将application、protocol、register注册到service
        serviceConfig.setRegistry(registryConfig);
        serviceConfig.setProtocol(protocolConfig);
        serviceConfig.setApplication(applicationConfig);
        serviceConfig.export();

        System.out.println("服务已经暴露");
        System.in.read();
    }
}
